package com.security.config.mobile;

import com.security.system.dao.SysUserDao;
import com.security.system.entity.SysUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 通过手机号获取用户信息和权限资源
 */
@Slf4j
@Component("mobileUserDetailsService")
public class MobileUserDetailsService implements UserDetailsService {

    @Resource
    SysUserDao dao;

    @Override
    public UserDetails loadUserByUsername(String mobile) throws UsernameNotFoundException {
        log.info("请求认证的手机号是："+mobile);
        SysUser sysUser = dao.findSysUserByMobile(mobile);
        return sysUser;
    }
}
